﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;

namespace OperateLogLibrary
{
    public class OperateLog
    {
        public TextBox LogTextBox;
        public OperateLog(TextBox logTextBox)
        {
            LogTextBox = logTextBox;
        }
        public OperateLog()
        {
           
        }
        delegate void Callback( string msg);
        public  void SetLog(string msg)
        {
            if (LogTextBox == null)
                return;

            if (LogTextBox.Parent.InvokeRequired)
            {
                Callback cb = new Callback(SetLog);
                LogTextBox.Parent.Invoke(cb, new object[] { msg });
                return;
            }
            
            LogTextBox.AppendText(msg + "【" + DateTime.Now.ToString() + "】\r\n\r\n");
            LogTextBox.SelectionStart = LogTextBox.Text.Length;
            LogTextBox.ScrollToCaret();
            LogTextBox.Focus();
        }
    }
}
